package com.shop.controller;

import com.shop.annotation.RequiresPermissionsDesc;
import com.shop.pojo.DtsAccountTrace;
import com.shop.pojo.DtsUserAccount;
import com.shop.service.DtsAccountTraceService;
import com.shop.util.ResponseUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @ClassName AdminBrokerageController
 * @Author xiao宋
 * @Date 18:01  2022/10/15
 * @Version 1.0
 * @Description TODO
 */
@Slf4j
@RestController
@RequestMapping("/admin/brokerage")
public class AdminBrokerageController {
    @Autowired
    DtsAccountTraceService accountTraceService;

    /**
     * 佣金管理处分页显示数据
     *
     * @param page
     * @param limit
     * @param sort
     * @param order
     * @param statusArray
     * @param username
     * @param mobile
     * @return
     * todo 最后这个参数接收不到有空研究一下。
     */
    @RequiresPermissions("admin:brokerage:list")
    @RequiresPermissionsDesc(menu = {"系统管理", "角色管理"}, button = "佣金管理")
    @GetMapping("/list")
    public Object list(
            @RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
            @RequestParam(value = "limit", required = false, defaultValue = "20") Integer limit,
            @RequestParam(value = "sort", required = false, defaultValue = "add_time") String sort,
            @RequestParam(value = "order", required = false, defaultValue = "desc") String order,
            @RequestParam(value = "statusArray", required = false, defaultValue = "") List<Integer[]> statusArray,
            String username,
            String mobile    ) {

        //            @RequestParam(value = "statusArray", required = false, defaultValue = "") List<String> statusArray,
//            @RequestParam(value = "statusArray", required = false, defaultValue = "") Map<String,Integer[]> statusArray,
//            String []statusArray,
        log.debug("开始执行佣金管理分页列表");
        System.out.println(statusArray);
        log.debug("前端传的数组：{}",statusArray);
        Map<String, Object> data = accountTraceService.findByPage(page, limit, sort, order, username, mobile, statusArray);
        return ResponseUtil.ok(data);
//        return ResponseUtil.ok();
    }

    /**
     * 佣金审批操作
     * @return
     */
    @RequiresPermissions("admin:user:update")
    @RequiresPermissionsDesc(menu = {"系统管理", "用户管理"}, button = "佣金审批")
    @PostMapping("/approve")
    public Object approve(@RequestBody DtsAccountTrace account) {
        boolean flag = accountTraceService.approve(account);
        if (flag) {
            return ResponseUtil.ok();
        } else {
            return ResponseUtil.fail(-1, "更新数据失败");
        }
    }


}
